<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kucha\ueditor\UEditor;
use yii\helpers\ArrayHelper;
use yii\web\View;

/* @var $this yii\web\View */
/* @var $model common\models\Goods */
/* @var $form yii\widgets\ActiveForm */
$this->registerCssFile('/uploadImg/css/fileinput.css');
$this->registerCssFile('/uploadImg/css/default.css');
$this->registerJsfile('/uploadImg/js/fileinput.js', [
    'depends' => 'yii\web\YiiAsset',
    'position' => \yii\web\View::POS_END
]);
$js = '';
$this->registerJs('function display(){
        if($("#goods-pid").val()==0){
        alert("请选择栏目");
    return false;
        }
    return true;
    }',View::POS_HEAD);
$this->registerJs('
    
    $("#color").click(function(){

    $("#colortable").append(\'<tr><td  class="col-xs-5 col-sm-5 col-md-5"><input class="form-control" type="text" name="GoodsType[name][]"></td><td  class="col-xs-5 col-sm-5 col-md-5"><input class="form-control" type="text" name="GoodsType[price][]"></td><td class="btn btn-danger"  onclick="$(this).parent().remove()">删除</td></tr>\');
});
    $("#message").click(function(){
	var val=$("#text_content").val();
    var strs= new Array(); //定义一数组 
    val=val.replace(/cm|kg|厘米/g,"");
    val=val.replace(/厚度/g,"刃厚");
    val=val.replace(/净重/g,"重量");
    val=val.replace(/刃材质/g,"刃材");
    val=val.replace(/鞘材质/g,"鞘材");
    val=val.replace(/全长/g,"总长");
    val=val.replace(/刃最宽/g,"刃宽");
    val=val.replace(/：/g,"");
	var va=val.replace(/(总长|名称|重量|刃长|刃宽|柄长|刃厚|刃材|鞘材|装具|工艺|赠品|硬度)/g,"&$1:");
    console.log(va);
    strs=va.split("&"); //字符分割 
    var str=new Array();
    for (i=1;i<strs.length ;i++ ) 
    { 
        str=strs[i].split(":");
        if(str.length==2){
            $("form label").each(function(){
                if($(this).html()==str[0]){
                $(this).next().val($.trim(str[1]));
                }
            })
        }
    } 
});');
?>

<div class="goods-form">
<div class="col-xs-10 col-sm-10 col-md-10" >
<label class="control-label" >字段生成工具</label>
<textarea rows="3" class="form-control" id='text_content'>
</textarea>
</div>

<div class="form-group" style="clear: both">
        <button type="button" class="btn btn-success" id='message'>生成</button>    </div>
<hr class="col-xs-12 col-sm-12 col-md-12" >
<script>

</script>
    <?php $form = ActiveForm::begin(); ?>
    <div class="col-xs-1 col-sm-2 col-md-2 field-goods-pid required">
		<label class="control-label" for="goods-pid">上级栏目</label> <select
			id="goods-pid" class="form-control" name="Goods[pid]">
			<option value=0>请选择</option>
            <?php if(!empty($parent[0])):?>
                <?php foreach($parent[0] as $val):?>
                    <optgroup label="<?=$val['name']?>">
                        <?php if(!empty($parent[$val['id']])):?>
                        <?php foreach($parent[$val['id']] as $v):?>
                        	<option value="<?=$v['id']?>" <?php if($model->pid==$v['id']):?>selected="true"<?php endif;?>><?=$v['name']?></option>
                        <?php endforeach;?>
                        <?php endif;?>
                    </optgroup>
                <?php endforeach;?>
            <?php endif;?>
		</select>
	</div>
    
    <?= $form->field($model, 'name',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput(['maxlength' => true])?>

    <?= $form->field($model, 'price',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput(['maxlength' => true])?>

    <?= $form->field($model, 'num',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput(['value'=>188])?>

    <?= $form->field($model, 'sumlen',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput()?>
	<?= $form->field($model, 'hot',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->dropDownList(['否','是'])?>
	<?= $form->field($model, 'tag',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->dropDownList(['无','新品','特价','人气'])?>
    <?= $form->field($model, 'bladelen',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput()?>

    <?= $form->field($model, 'stemlen',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput()?>

    <?= $form->field($model, 'width',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput()?>

    <?= $form->field($model, 'height',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput()?>

    <?= $form->field($model, 'hard',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput()?>

    <?= $form->field($model, 'weight',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput()?>
    <?= $form->field($model, 'stuff',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput(['maxlength' => true])?>

    <?= $form->field($model, 'sheath',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput(['maxlength' => true])?>

    <?= $form->field($model, 'grind',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput(['maxlength' => true])?>

    <?= $form->field($model, 'craftwork',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput(['maxlength' => true])?>


    <?= $form->field($model, 'gift',['options'=>['class'=>'col-xs-1 col-sm-2 col-md-2']])->textInput(['maxlength' => true,'value'=>'刀油+锦盒+收藏证书'])?>

    <?= $form->field($model, 'logo',['options'=>['class'=>'col-xs-3 col-sm-3 col-md-4']])->fileInput()?>
    <?php for($i=0;$i<4;$i++):?>	
    <?php if(isset($imgs[$i])):?>
    <input type='hidden' name=Goodsfile[id][<?=$i?>] value=<?=$imgs[$i]['id']?>>
    <?php $js.="$('#goodsfile-name{$i}').fileinput({'showUpload':false,'initialPreview':['{$imgs[$i]['name']}'],'msgSelected':'{n}个文件已上传','allowedFileExtensions' : ['jpg', 'png','gif','jpeg']});";?>
    <?php else:?>
    <?php $js.="$('#goodsfile-name{$i}').fileinput({'showUpload':false,'initialPreview':[],'msgSelected':'{n}个文件已上传','allowedFileExtensions' : ['jpg', 'png','gif','jpeg'],});";?>
   
    <?php endif;?>
    <?= $form->field($fmodel, "name[{$i}]",['options'=>['class'=>'col-xs-3 col-sm-3 col-md-2']])->fileInput(['id'=>'goodsfile-name'.$i])?>
     <?php endfor;?>
     <div class="col-xs-12 col-sm-12 col-md-12" id="color">
     <hr/>
     <a class="btn btn-primary" href="javascript:;" onclick="">添加颜色</a>
     <hr/>
     </div>
     <div class="col-xs-12 col-sm-12 col-md-12">
     <table class="col-xs-6 col-sm-6 col-md-6" id='colortable'>
     <tr>
     <td class="col-xs-5 col-sm-5 col-md-5">颜色</td>
     <td class="col-xs-5 col-sm-5 col-md-5">价格</td>
     </tr>
     <?php if(!empty($colors)):?>
     <?php foreach($colors as $val):?>
      <tr>
      <input type='hidden' name='GoodsType[id][]' value='<?=$val['id']?>'>
     	<td  class="col-xs-5 col-sm-5 col-md-5">
     <input class="form-control" type="text" name="GoodsType[name][]" value="<?=$val['name']?>"></td>
     	<td  class="col-xs-5 col-sm-5 col-md-5">
     <input class="form-control" type="text" name="GoodsType[price][]" value="<?=$val['price']?>">
     </td>
     <td class="btn btn-danger" onclick="$(this).parent().remove()">删除</td>
     </tr>
     <?php endforeach;?>
     <?php endif;?>
    
     </table></div>
    <?=$form->field($model, 'message', ['options' => ['class' => 'col-xs-12 col-sm-12 col-md-12']])->widget(UEditor::className(), ['clientOptions' => ['initialFrameHeight' => 200,'zIndex' => 1,'toolbars' => [['fullscreen','source','undo','redo','snapscreen','simpleupload','insertimage','justifyleft','justifyright','justifycenter','justifyjustify'],['bold','italic','underline','fontborder','strikethrough','superscript','subscript','removeformat','formatmatch','autotypeset','blockquote','pasteplain','|','forecolor','backcolor','insertorderedlist','insertunorderedlist','selectall','cleardoc']]]])?>



    <div class="form-group" style='clear: both'>
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary','onclick'=>'return display()'])?>
    </div>

    <?php ActiveForm::end(); ?>
    <?php
    $logo = $model->logo != '' ? "'{$model->logo}'" : '';
    $js .= "$('#goods-logo').fileinput({'showUpload':false,'initialPreview':[{$logo}],'msgSelected':'{n}个文件已上传','allowedFileExtensions' : ['jpg', 'png','gif','jpeg'],});
	";
    $this->registerJs($js);
    ?>

</div>
